package com.cn.crmsystem.service.customerService.impl;

import com.cn.crmsystem.mapper.customerMapper.VisitMapper;
import com.cn.crmsystem.pojo.Login;
import com.cn.crmsystem.pojo.ResultJson;
import com.cn.crmsystem.pojo.User;
import com.cn.crmsystem.pojo.Visit;
import com.cn.crmsystem.service.customerService.VisitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class VisitServiceImpl implements VisitService {

    @Autowired
    private VisitMapper visitMapper;
    
    @Override
    public ResultJson insertVisit(Visit visit, Login login) {
        HashMap<Object, Object> map = new HashMap<>();
        map.put("visit",visit);
        map.put("login",login);
        if(visitMapper.insertVisit(map)>0){
            return new ResultJson<>().getSuccess("添加成功");
        }else{
            return new ResultJson<>().getSuccess("添加失败");
        }
    }

    @Override
    public ResultJson deleteVisit(Integer id) {
        if(visitMapper.deleteVisit(id)>0){
            return new ResultJson<>().getSuccess("删除成功");
        }else{
            return new ResultJson<>().getSuccess("删除失败");
        }
    }

    @Override
    public ResultJson updateVisit(Visit visit) {
        if(visitMapper.updateVisit(visit)>0){
            return new ResultJson<>().getSuccess("修改成功");
        }else{
            return new ResultJson<>().getSuccess("修改失败");
        }
    }

    @Override
    public ResultJson updateVisitUser(Integer id) {
        if(visitMapper.updateVisitUser(id)>0){
            return new ResultJson<>().getSuccess("修改成功");
        }else{
            return new ResultJson<>().getSuccess("修改失败");
        }
    }


    @Override
    public ResultJson<List> selectVisit(Map<String, Object> map) {
        List list =visitMapper.selectVisit(map);
        Long count=visitMapper.selectVisitCount(map);
        if(list!=null && list.size()>0){
            return new ResultJson<>().getSuccess("查询成功",list,count);
        }else{
            return new ResultJson<>().getSuccess("查询失败",list,count);
        }
    }

    @Override
    public ResultJson deleteAllVisit(Integer[] ids) {
        int result=0;
        for(int i=0;i<ids.length;i++){
            result=visitMapper.deleteVisit(ids[i]);
        }
        if(result>0){
            return new ResultJson<>().getSuccess("删除成功");
        }else{
            return new ResultJson<>().getSuccess("删除失败");
        }
    }
}
